***************************************************
*** SUMMARIZE AUDIT STRATEGIES ACROSS REGIONS   ***
*** Last edited: 3/1/21         		   	    ***
***************************************************

log using "${CodePath}/log/summarize_auditstrategies_$S_DATE.log", text replace

cap mkdir "${OutputPath}/Summary Statistics/"
cap mkdir "${OutputPath}/Summary Statistics/byfyear"


use "${DataPath}/derived/hospyear_0716_jk.dta", clear
keep if !missing(RACregion_audit_in2011) //restrict to acute hospitals

// define sample of hospitals within 100 miles
preserve
	use "${DataPath}/within100m/pnlist_groups_100m.dta", clear
	duplicates drop pn, force
	keep pn
	gen sample_hosp_100mradius = 1
	tempfile temp
	save `temp'
restore

merge m:1 pn using `temp', keep(1 3) nogen
replace sample_hosp_100mradius = 0 if missing(sample_hosp_100mradius)

// by RAC region over time 
	// calculate means

	preserve
		keep if sample_total == 1
		
		gcollapse (mean) n_claims n_claims_02 auditrate_in demandrate_in demandafterauditrate_in real_gcost_admin_net app_live_136 app_contracting_136, by(RACregion fyear)
		gen admin_mill = real_gcost_admin_net/1e6

		keep if fyear>= 2007 & fyear <= 2015

		foreach var of varlist n_claims n_claims_02 admin_mill{
			if "`var'" == "n_claims"{
				local lab = "Mean admissions"
			}
			if "`var'" == "n_claims_02"{
				local lab = "Mean admissions, LOS = 0-2"
			}
			if "`var'" == "admin_mill"{
				local lab = "Mean admin costs (million $)"
			}

			twoway (connected `var' fyear if RACregion == 1, color(dknavy) msymbol(O)) (connected `var' fyear if RACregion == 2, color(maroon) msymbol(Oh)) ///
				(connected `var' fyear if RACregion == 3, color(forest_green) msymbol(D)) (connected `var' fyear if RACregion == 4, color(dkorange) msymbol(Th)), ///
				legend(order(1 "A" 2 "B" 3 "C" 4 "D") col(4)) ///
				graphregion(color(white)) xtitle("Year") ytitle("") ///
				subtitle("`lab'", position(11) justification(left) size(med)) ///
				ylabel(,angle(horizontal))  ///
				xlabel(2007(1)2015) ///
				xline(2010.75, lpattern(dash) lcolor(black))
			graph export "${OutputPath}/Summary Statistics/byfyear/byRACregion_mean_`var'_overall.pdf", replace
			
		}

		foreach var of varlist auditrate_in demandrate_in{
			keep if fyear >= 2009
			if "`var'" == "auditrate_in"{
				local lab = "Mean audit rate (%)"
			}

			if "`var'" == "demandrate_in"{
				local lab = "Mean denial rate (%)"
			}

			twoway (connected `var' fyear if RACregion == 1, color(dknavy) msymbol(O)) (connected `var' fyear if RACregion == 2, color(maroon) msymbol(Oh)) ///
				(connected `var' fyear if RACregion == 3, color(forest_green) msymbol(D)) (connected `var' fyear if RACregion == 4, color(dkorange) msymbol(Th)), ///
				legend(order(1 "A" 2 "B" 3 "C" 4 "D") col(4)) ///
				graphregion(color(white)) xtitle("Year") ytitle("") ///
				subtitle("`lab'", position(11) justification(left) size(med)) ///
				ylabel(,angle(horizontal))  ///
				xlabel(2009(1)2015) ///
				xline(2010.75, lpattern(dash) lcolor(black))
			graph export "${OutputPath}/Summary Statistics/byfyear/byRACregion_mean_`var'_overall.pdf", replace
			
		}

		foreach var of varlist  demandafterauditrate_in{
			keep if fyear >= 2010
			if "`var'" == "demandafterauditrate_in"{
				local lab = "Mean demand after audit (%)"
			}
			if "`var'" == "app_live_136"{
				local lab = "Share hospitals with MN checking app"
			}
			if "`var'" == "app_contracting_136"{
				local lab = "Share hospitals installing/upgrading MN checking app"
			}


			twoway (connected `var' fyear if RACregion == 1, color(dknavy) msymbol(O)) (connected `var' fyear if RACregion == 2, color(maroon) msymbol(Oh)) ///
				(connected `var' fyear if RACregion == 3, color(forest_green) msymbol(D)) (connected `var' fyear if RACregion == 4, color(dkorange) msymbol(Th)), ///
				legend(order(1 "A" 2 "B" 3 "C" 4 "D") col(4)) ///
				graphregion(color(white)) xtitle("Year") ytitle("") ///
				subtitle("`lab'", position(11) justification(left) size(med)) ///
				ylabel(,angle(horizontal))  ///
				xlabel(2010(1)2015) ///
				xline(2010.75, lpattern(dash) lcolor(black))
			graph export "${OutputPath}/Summary Statistics/byfyear/byRACregion_mean_`var'_overall.pdf", replace
		} 
	
	restore


log close
